package huoye.shops.huoye.operation.activity;

import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.codeideology.android.AXIFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import huoye.shops.R;
import huoye.shops.base.BaseActivity;
import huoye.shops.base.UserManager;
import huoye.shops.huoye.operation.fragment.VipPowerFragment;
import huoye.shops.huoye.operation.model.ObtainShopType;
import huoye.shops.huoye.operation.presenter.BangBoBlackCardPresenter;
import huoye.shops.huoye.operation.view.IBangBoBlackCardView;
import huoye.shops.huoye.operation.widget.HintTitleDialog;
import huoye.shops.utils.StockUtils;

public class BangBoBlackCardActivity extends BaseActivity implements IBangBoBlackCardView{

    private BangBoBlackCardPresenter mBangBoBlackCardPresenter;

    @OnClick(R.id.bangbo_black_card_tv_vip_guests)
    void onVipGuestsClick(){
        startActivity(VipGuestsActivity.class);
    }
    @OnClick(R.id.bangbo_black_card_tv_add_bang_bo)
    void onAddClick(){
        showAddBangBoDialog();
    }
    @OnClick(R.id.bangbo_black_card_tv_add_bang_bo_shop)
    void onAddShopClick(){
        startActivity(AddAllinceActivity.class);
    }


    @BindView(R.id.bangbo_black_card_tv_add_bang_bo)
    TextView tvAddBangBo;
    @BindView(R.id.bangbo_black_card_tv_add_bang_bo_shop)
    TextView tvAddShop;

    @BindView(R.id.bangbo_black_card_tv_state)
    TextView tvState;

    @BindView(R.id.base_toolbar_tl)
    TabLayout tl;
    @BindView(R.id.base_toolbar_vp)
    ViewPager vp;


    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    AXIFragmentPagerAdapter myFragmentPagerAdapter;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_bang_bo_black_card;
    }

    @Override
    protected void initView(@Nullable Bundle bundle) {
        setTitle("帮播黑卡");


        mBangBoBlackCardPresenter = new BangBoBlackCardPresenter();
        mBangBoBlackCardPresenter.addTaskListener(this);
        mBangBoBlackCardPresenter.onStart();

      //  mBangBoBlackCardPresenter.getObtainShopType();

        fragments.add(VipPowerFragment.getInstan(VipPowerFragment.TYPE_POWER_BLACK_CARD));
        fragments.add(VipPowerFragment.getInstan(VipPowerFragment.TYPE_POWER_ALLIANCE));
        titles.add(getString(R.string.operation_power_black_card));
        titles.add(getString(R.string.operation_power_alliance));
        StockUtils.reflex(tl);
        myFragmentPagerAdapter = new AXIFragmentPagerAdapter(getSupportFragmentManager(),fragments, titles);
        vp.setAdapter(myFragmentPagerAdapter);
        vp.setOffscreenPageLimit(fragments.size());
        tl.setupWithViewPager(vp);

        setCardType();

    }

    private void setCardType(){
        int iCardType = UserManager.getInstance().getCardType();
        switch (iCardType){
            case 0:
                tvState.setText("未加入");
                break;
            case 1:
                tvState.setText("已加入联盟商家");
                tvAddShop.setVisibility(View.GONE);
                break;
            case 2:
                tvState.setText("已加入黑卡用户");
                tvAddBangBo.setVisibility(View.GONE);
                tvAddShop.setVisibility(View.GONE);
                break;
        }
    }




    private void showAddBangBoDialog(){
        HintTitleDialog hintTitleDialog = new HintTitleDialog(this);
        hintTitleDialog.setOnHintTitleListener(new HintTitleDialog.OnHintTitleListener() {
            @Override
            public void onLeftClick() {

            }

            @Override
            public void onRightClick() {
                mBangBoBlackCardPresenter.JoinShopCardType("2","");
            }
        });
        hintTitleDialog.show();
        hintTitleDialog.setDialogContent("提示","您确认加入帮播黑卡商家？","不,谢谢","确认");
        hintTitleDialog.setCanceledOnTouchOutside(false);
    }


    @Override
    public void getShopType() {
        int iCardType = UserManager.getInstance().getCardType();
        switch (iCardType){
            case 0:
                tvState.setText("未加入");
                break;
            case 1:
                tvState.setText("已加入联盟商家");
                tvAddShop.setVisibility(View.GONE);
                break;
            case 2:
                tvState.setText("已加入黑卡用户");
                tvAddBangBo.setVisibility(View.GONE);
                tvAddShop.setVisibility(View.GONE);
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if(mBangBoBlackCardPresenter != null){
            setCardType();
        }
    }
}
